<%--
  Created by IntelliJ IDEA.
  User: Elle
  Date: 2022/12/26
  Time: 16:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加员工</title>
</head>
<body>
<div>
    <form action="PersonAddServlet" method="post" id="myform" >
        <p><h3>添加人员</h3></p>
        <p>姓名：<input type="text" name="name" id="name"></p>
        <p>性别：<select name="sex">
            <option value="0">请选择</option>
            <option value="男">男</option>
            <option value="女">女</option>
        </select>
        </p>
        <p>年龄：<input type="text" name="age"></p>
        <p>等级：<select name="rank">
            <option value="0">请选择</option>
            <option value="1级">1级</option>
            <option value="2级">2级</option>
            <option value="3级">3级</option>
        </select></p>
        <p>部门：<select name="department">
            <option value="0">请选择</option>
            <option value="开发">开发</option>
            <option value="人事">人事</option>
            <option value="测试">测试</option>
        </select></p>
        <p><input type="button"  value="提交" onclick="check()"></p>
    </form>
</div>
</body>
<script src="js/jquery.js"></script>
<script>
    function check() {
        console.log('验证');
        //非空验证
        //格式验证
        //同名验证==》姓名不能重复
        var name = $("#name").val();
        $.ajax({
            url:"CheckNameServlet", //地址
            data:{"name":name}, //传递的参数
            success:function (data) { //成功，服务器正确==>out输出的内容
                if(data=="ok"){
                   //存在
                    alert('用户名已存在，请重新输入');
                }else{
                    //验证成功==》表单提交
                    $("#myform").submit();
                }
            }
        });
    }
</script>
</html>
